<template>
  <view
    v-if="visible"
    class="ad-popup-overlay"
    @tap="handleOverlayTap"
  >
    <view
      class="ad-popup-container"
      @tap.stop
    >
      <view class="ad-content">
        <image
          src="/static/images/index/ad.png"
          class="ad-image"
          @tap="handleAdTap"
        ></image>
      </view>

      <view
        class="close-btn"
        @tap="closePopup"
      >
        <image
          src="/static/images/index/close.png"
          class="close-icon"
          mode="aspectFit"
        ></image>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: "AdPopup",
  props: {
    visible: {
      type: Boolean,
      default: false
    },
  },
  methods: {
    closePopup() {
      this.$emit("close")
    },
    handleOverlayTap() {
      this.closePopup()
    },
    handleAdTap() {
      this.$emit("ad-click")
    }
  }
}
</script>

<style lang="scss" scoped>
.ad-popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40rpx;
}

.ad-popup-container {
  position: relative;
  width: 100%;
  max-width: 600rpx;
  background-color: transparent;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.close-btn {
  width: 60rpx;
  height: 60rpx;
  z-index: 10;
}

.close-icon {
  width: 60rpx;
  height: 60rpx;
}

.ad-content {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-image {
  width: 600rpx;
  height: 808rpx;
}

.ad-popup-overlay {
  animation: fadeIn 0.3s ease-out;
}

.ad-popup-container {
  animation: slideIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    transform: scale(0.8) translateY(-50rpx);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

@media screen and (max-width: 750rpx) {
  .ad-popup-overlay {
    padding: 20rpx;
  }

  .ad-popup-container {
    max-width: 100%;
  }
}
</style>
